import 'package:flutter/material.dart';
import 'package:flutter2/widget/base/base_container.dart';

// ignore: must_be_immutable
class CheckBox extends StatefulWidget {
  CheckBox({
    super.key,
    required this.check,
    required this.checkIcon,
    required this.uncheckIcon,
    this.onChange,
  });

  bool check;
  final String checkIcon;
  final String uncheckIcon;
  final Function(bool check)? onChange;

  @override
  State<CheckBox> createState() => _CheckBoxState();
}

int time = 0;

class _CheckBoxState extends State<CheckBox> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        int cur = DateTime.now().millisecondsSinceEpoch;
        if (cur - time < 500 && time != 0) return;
        time = cur;
        setState(() {
          widget.check = !widget.check;
          widget.onChange?.call(widget.check);
        });
      },
      child: BaseContainer(
        width: 15,
        height: 15,
        backgroundImg: widget.check ? widget.checkIcon : widget.uncheckIcon,
      ),
    );
  }
}
